<div id="module_login" <?php echo (!$member ? '':'style="display:none;"');?>>
<!--	<span>
		&nbsp;
	</span>
	<a href="javascript:void(0);" id="module_login_floating_toggle">เข้าระบบ</a>
	<span>
		|
	</span>
	<a href="http://my.you2play.com/">
		สมัครสมาชิก
	</a>
	<span>
		&nbsp;
	</span>-->
	<div id="fb-login">
		<div id="fb-root">
		</div>
		<script>
			window.fbAsyncInit = function()
			{
				// init the FB JS SDK
				FB.init(
					{
						appId      : '<?php echo $this->config->item("fb_api");?>', // App ID from the App Dashboard
						//channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File for x-domain communication
						status     : true, // check the login status upon init?
						cookie     : true, // set sessions cookies to allow your server to access the session?
						xfbml      : true  // parse XFBML tags on this page?
					});

				// Additional initialization code such as adding Event Listeners goes here
/*				FB.getLoginStatus(function(response)
					{
						if (response.status === 'connected')
						{
							// connected
							$('#module_login').hide();
							$('#module_logout').show();
						} else if (response.status === 'not_authorized')
						{
							// not_authorized
						} else
						{
							// not_logged_in
						}
					});*/
			};

			// Load the SDK's source Asynchronously
			// Note that the debug version is being actively developed and might
			// contain some type checks that are overly strict.
			// Please report such bugs using the bugs tool.
			(function(d, debug)
				{
					var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
					if (d.getElementById(id))
					{
						return;
					}
					js = d.createElement('script'); js.id = id; js.async = true;
					js.src = "//connect.facebook.net/th_TH/all" + (debug ? "/debug" : "") + ".js";
					ref.parentNode.insertBefore(js, ref);
				}(document, /*debug*/ false));

			//Login && Logout
			function fbLogin(e)
			{
				$('#fbStatus').find('.spinner').show();
				FB.login(function(response)
					{
						if (response.authResponse)
						{
							// connected
							FB.api('/me', function(response) {
								$.ajax({
									url:web_path+'ajax_member_login',
									type:'post',
									data:({
										fb_id:response.id,
										username:response.username
									}),
									dataType:'json'
								}).done(function(data){
									$('#fbStatus').find('.spinner').hide();
									if(data.error == 1){
										alert(data.msg);
									} else {
										//Set Memer
										$('.memberName').html(''+data.member.username+'');
										//Show Result
										$('#module_login').hide();
										$('#module_logout').show();
									}
								});									
							});
						} else
						{
							// cancelled
							//window.location.href = window.location.href.replace(window.location.hash,'');
						}
					},{scope: 'email,publish_actions,read_stream,offline_access'});
			}

			function memberLogout()
			{
				$.ajax({
					url:web_path+'ajax_member_logout',
					type:'get'
				}).done(function(data){
					//Show Result
					$('#module_logout').hide();
					$('#module_login').show();	
				});					
			}
		</script>
		<div id="fbStatus">
			<a class="fb login" href="javascript:void(0);" onclick="javascript:fbLogin(this);"></a>
			<span class="spinner"></span>
		</div>
	</div>
</div>
<div id="module_logout" <?php echo (!$member ? 'style="display:none;"':'');?>>
	<span>
		&nbsp;
	</span>
	<a href="javascript:void(0);" onclick="javascript:memberLogout();">ออกจากระบบ</a>
	<span>
		|
	</span>
	<a href="http://my.you2play.com/" class="memberName" target="_blank"><?php echo @$member['username'];?></a>
</div>
<!--Floating Login-->
<div id="module_login_floating">
	<div class="arrowUp"></div>
	<div class="floatLeft">
		<input type="text" name="f_username" id="f_username" class="input" placeholder="username" autocomplete="off"/>
		<input type="password" name="f_password" id="f_password" class="input" placeholder="password" autocomplete="off"/>
	</div>
	<div class="floatRight">
		<a href="javascript:void(0);" class="btnLogin"></a>
	</div>
	<div class="clear"></div>
	<input type="checkbox" name="f_rememberme" id="f_rememberme"> บันทึกรหัสผ่าน l <a href="<?php echo $main_url.'member/forgot_password/';?>" target="_self">ลืมรหัสผ่าน</a>
</div>